const communityModel = require('../models/communityModel');
const merchantService = require('./merchantService');
const create = async(ctx, next) => {
    const req = ctx.request.body;
    const data = Object.assign({}, req);
    const result = await communityModel.create(data);
    if (result) {
        ctx.body = {
            code: 1,
            msg: '添加成功！',
            data: {}
        };
    }
}

const update = async(data) => {
    const community = await find();
    await communityModel.update({
        _id: community._id,
    }, data);
}

const find = async(ctx, next) => {
    const result = await communityModel.find();
	let merchantId = result[0].merchantId;
	const merchant = await merchantService.findById(merchantId);
	const data = result[0]._doc;
	data.merchant = merchant;
	if (result) {
        ctx.body = {
            code: 1,
            msg: '',
            data
        };
    }
}

module.exports = {
    create,
    update,
    find
};